﻿using ArtMath.CommonType;
using ArtMath.Component;
using ArtMath.Converter;
using ArtMath.Core.Helper;
using ArtMath.Flag;
using ArtMath.Resource;
using ArtMath.Setting;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Reflection;
using System.Security;
using System.Windows.Forms;

namespace ArtMath.Window
{
    public partial class SplashScreenWindow : Form
    {
        KeyValuePair<Action, string>[] inits;
        public SplashScreenWindow()
        {
            InitializeComponent();
            Text = Flags.SoftwareName;
            Size sz = ClientSize - pbTitle.Size;
            pbTitle.Location = new Point(sz.Width >> 1, sz.Height >> 1);
            inits = new KeyValuePair<Action, string>[]
            {
                //new KeyValuePair<Action, string>(startAdministrator, "XX"),
                new KeyValuePair<Action, string>(initToolBox, Resources.Translate("InitToolBox")),
                new KeyValuePair<Action, string>(initSettings, Resources.Translate("InitSettingsWindow")),
                new KeyValuePair<Action, string>(initMain, Resources.Translate("InitMainWindow")),
            };
        }
        public ToolsWindow.InitializationData ToolsWindowData { get; private set; }
        public MainWindow.InitializationData MainWindowData { get; private set; }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 0; i < inits.Length; i++)
            {
                backgroundWorker1.ReportProgress(i, inits[i].Value + "...");
                inits[i].Key?.Invoke();
                if (backgroundWorker1.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
            backgroundWorker1.ReportProgress(inits.Length, Resources.Translate("Complete"));
        }
        void ConstructionMenuItems_Click(object sender, EventArgs e)
        {
            Program.WinTools.LinkedPad.BuildComponents((ToolTypeName)(sender as ToolStripMenuItem).Tag);
        }
        void MeasureMenuItems_Click(object sender, EventArgs e)
        {
            Program.WinTools.LinkedPad.BuildCalculatedParameter((ToolTypeName)(sender as ToolStripMenuItem).Tag);
        }
        void startAdministrator()
        {
            Process admin = Utility.GetProcess($"{Flags.SoftwareName}.Administrator");
            if (admin == null)
            {
                Process.Start($"{Flags.SoftwareName}.Administrator.exe");
            }
        }
        void initMain()
        {
            MainWindowData = new MainWindow.InitializationData();
            ToolTypeName[] cons = new ToolTypeName[] { ToolTypeName.zd, ToolTypeName.jd, ToolTypeName.zx,
                ToolTypeName.dbxzx, ToolTypeName.sjxwx, ToolTypeName.sjxnx, ToolTypeName.sjxcx, ToolTypeName.dhs,
                    ToolTypeName.zz, ToolTypeName.pxx, ToolTypeName.cx, ToolTypeName.zcx, ToolTypeName.cxd,
                ToolTypeName.qx, ToolTypeName.jpfx, ToolTypeName.zz, ToolTypeName.xljf, ToolTypeName.xljf_,
                    ToolTypeName.zz, ToolTypeName.wjy, ToolTypeName.nqy };
            MainWindowData.ConstructionMenuItems = new ToolStripItem[cons.Length];
            for (int i = 0; i < cons.Length; i++)
            {
                if (cons[i] == ToolTypeName.zz)
                {
                    MainWindowData.ConstructionMenuItems[i] = new ToolStripSeparator();
                }
                else
                {
                    MainWindowData.ConstructionMenuItems[i] = new ToolStripMenuItem(null, null, ConstructionMenuItems_Click)
                    {
                        Tag = cons[i]
                    };
                }
                MainWindowData.ConstructionMenuItems[i].Enabled = false;
            }
            cons = new ToolTypeName[] { ToolTypeName.ldjl, ToolTypeName.ddzxdjl, ToolTypeName.lzxjl,
                    ToolTypeName.lzxjj, ToolTypeName.lzxdj, ToolTypeName.lxldslj, ToolTypeName.lxldxlj };
            MainWindowData.MeasureMenuItems = new ToolStripItem[cons.Length];
            for (int i = 0; i < cons.Length; i++)
            {
                if (cons[i] == ToolTypeName.zz)
                {
                    MainWindowData.MeasureMenuItems[i] = new ToolStripSeparator();
                }
                else
                {
                    MainWindowData.MeasureMenuItems[i] = new ToolStripMenuItem(null, null, MeasureMenuItems_Click)
                    {
                        Tag = cons[i]
                    };
                }
                MainWindowData.MeasureMenuItems[i].Enabled = false;
            }
            MainWindowData.RecentDocumentMenuItems = new List<ToolStripItem>();
            int index = 0;
            foreach (Tuple<string, string> doc in UserOptions.Instance.RecentDocuments)
            {
                ToolStripMenuItem item = new ToolStripMenuItem($"&{index++} {doc.Item1} [{doc.Item2}]") { Tag = doc };
                MainWindowData.RecentDocumentMenuItems.Add(item);
            }
        }
        void initSettings()
        {
            SettingsWindow.InitData = new SettingsWindow.InitializationData();
            SettingsWindow.InitData.LangField = typeof(Settings).GetField("Language");
            foreach (FieldInfo item in typeof(Settings).GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                object[] attr = item.GetCustomAttributes(typeof(Settings.InVisibleAttribute), true);
                if (attr?.Length > 0) continue;
                SettingsWindow.NamedField lbi = new SettingsWindow.NamedField(item);
                if (item.FieldType == typeof(Color))
                {
                    SettingsWindow.InitData.Colors.Add(lbi);
                }
                else if (item.FieldType == typeof(Font))
                {
                    SettingsWindow.InitData.Fonts.Add(lbi);
                }
                else if (item.FieldType == typeof(bool))
                {
                    SettingsWindow.InitData.Switches.Add(lbi);
                }
                else if (item.FieldType == typeof(int) || item.FieldType == typeof(float) || item.FieldType == typeof(double) ||
                    item.FieldType == typeof(string) && item != SettingsWindow.InitData.LangField)
                {
                    SettingsWindow.InitData.Numbers.Add(lbi);
                }
                else if (item.FieldType.IsEnum)
                {
                    SettingsWindow.InitData.Enumerations.Add(lbi);
                    EnumConverterBase ecb = lbi.Field.FieldType.GetConverter() as EnumConverterBase;
                    SettingsWindow.InitData.EnumConverters.Add(lbi, ecb.GetEnumValuesAndNames());
                }
            }
            Comparison<SettingsWindow.NamedField> cmp = (SettingsWindow.NamedField x, SettingsWindow.NamedField y) => { return x.Name.CompareTo(y.Name); };
            SettingsWindow.InitData.Switches.Sort(cmp);
            SettingsWindow.InitData.Numbers.Sort(cmp);
            SettingsWindow.InitData.Enumerations.Sort(cmp);
            for (int i = 8; i < 12; i++)
            {
                SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem(i.ToString()) { Tag = i });
            }
            for (int i = 12; i <= 28; i += 2)
            {
                SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem(i.ToString()) { Tag = i });
            }
            SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem("36") { Tag = 36 });
            SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem("48") { Tag = 48 });
            SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem("72") { Tag = 72 });
            if (Settings.Instance.Language == "zh-CN")
            {
                int startIndex = SettingsWindow.InitData.FontSizeItems.Count;
                string[] fs = new string[] { "初", "一", "二", "三", "四", "五", "六" };
                float[] size = new float[] { 42, 36, 26, 24, 22, 18, 16, 15, 14, 12, 10.5f, 9, 7.5f, 6.5f, 5.5f, 5 };
                foreach (string item in fs)
                {
                    SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem(item + "号"));
                    SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem("小" + item));
                }
                SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem("七号"));
                SettingsWindow.InitData.FontSizeItems.Add(new ListViewItem("八号"));
                for (int i = 0; i < size.Length; i++)
                {
                    SettingsWindow.InitData.FontSizeItems[startIndex + i].Tag = size[i];
                }
            }
            try
            {
                InstalledFontCollection fc = new InstalledFontCollection();
                foreach (FontFamily font in fc.Families)
                {
                    ListViewItem item = new ListViewItem(font.Name) { Font = new Font(font, 9) };
                    SettingsWindow.InitData.FontFamilyItems.Add(item);
                }
            }
            catch (Exception)
            {

            }
        }
        void foreachResourceImages<T>(Action<string, Image> act)
        {
            if (act == null) return;
            foreach (PropertyInfo item in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                Image img = item.GetValue(null, null) as Image;
                if (img == null) continue;
                act(item.Name.Substring(0, item.Name.Length - 4), img);
            }
        }
        void initToolBox()
        {
            ToolsWindowData = new ToolsWindow.InitializationData();
            ToolsWindowData.ToolListLargeIcon = new ImageList()
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize = new Size(32, 32),
                TransparentColor = Color.Transparent,
            };
            ToolsWindowData.ToolListSmallIcon = new ImageList()
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize = new Size(16, 16),
                TransparentColor = Color.Transparent,
            };
            foreachResourceImages<ToolIcons_Large>((string key, Image img) =>
            {
                ToolsWindowData.ToolListLargeIcon.Images.Add(key, img);
            });
            foreachResourceImages<ToolIcons_Small>((string key, Image img) =>
            {
                ToolsWindowData.ToolListSmallIcon.Images.Add(key, img);
            });
            ListViewGroup gp;
            //点
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "new_point", ToolTypeName.zyd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zbd", ToolTypeName.zbd));
            //构造点
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("轴对称", 74, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.zdc));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("中心对称", 73, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.zxdc));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zd", ToolTypeName.zd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dbfd", ToolTypeName.dbfd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jd", ToolTypeName.jd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zdbxzx", ToolTypeName.zx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zhongxin", ToolTypeName.dbxzx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "wx", ToolTypeName.sjxwx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "sjxnx", ToolTypeName.sjxnx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "chuixin", ToolTypeName.sjxcx));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("三角形旁心", 64, gp));
            //ToolsWindowData.ToolInfos.Add(new tool(toolTypeName.sjxpx));
            //函数
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "function", ToolTypeName.hs));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "csfc_zjzb", ToolTypeName.csfc));
            //构造函数
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dhs", ToolTypeName.dhs));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("原函数", 75, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.yhs));
            //线
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "ldxd", ToolTypeName.ldxd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "yxysxd", ToolTypeName.yxysxd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "ldsx", ToolTypeName.ldsx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "djssx", ToolTypeName.yssx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "ldzx", ToolTypeName.ldzx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dxszx", ToolTypeName.yszx));
            //构造线
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "pxx", ToolTypeName.pxx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "cx", ToolTypeName.cx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zcx", ToolTypeName.zcx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "cxd", ToolTypeName.cxd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "qxqx", ToolTypeName.qx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jpfx", ToolTypeName.jpfx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jndfx", ToolTypeName.jndfx));
            //角
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "ysj", ToolTypeName.ysj));
            //向量
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "vector", ToolTypeName.ldxl));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "ysxl", ToolTypeName.ysxl));
            //构造向量
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "xljf", ToolTypeName.xljf));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "xljf_", ToolTypeName.xljf_));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "pxxl", ToolTypeName.pxxl));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "czxl", ToolTypeName.czxl));
            //多边形
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "polygon", ToolTypeName.rydbx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zjsjx", ToolTypeName.zjsjx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dysjx", ToolTypeName.dysjx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dyzjsjx", ToolTypeName.dyzjsjx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dbsjx", ToolTypeName.dbsjx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "pxsbx", ToolTypeName.pxsbx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "rectangle", ToolTypeName.jx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "diamond", ToolTypeName.lx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "square", ToolTypeName.zfx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "tx", ToolTypeName.tx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dytx", ToolTypeName.dytx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zjtx", ToolTypeName.zjtx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "znbx", ToolTypeName.zdbx));
            //圆（弧）、扇形
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "yxysyd", ToolTypeName.yxddy));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "yxbj", ToolTypeName.yxbjy));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "zjy", ToolTypeName.zjy));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "sdy", ToolTypeName.sdy));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "sdh", ToolTypeName.sdyh));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "sdsx", ToolTypeName.sdsx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "bjyxjsx", ToolTypeName.bjyxjsx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "sdgx", ToolTypeName.sdgx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "xggx", ToolTypeName.xggx));
            //构造圆
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "qly", ToolTypeName.qly));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "wjy", ToolTypeName.wjy));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "nqy", ToolTypeName.nqy));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("旁切圆", 65, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.pqy));
            //圆锥曲线
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dczdzty", ToolTypeName.cdzty));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jdddty", ToolTypeName.jdddty));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jdzxty", ToolTypeName.jdzxty));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "ysty", ToolTypeName.ysty));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "szxzsqx", ToolTypeName.sxzsqx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jdydsqx", ToolTypeName.jdddsqx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jdxzsqx", ToolTypeName.jdxzsqx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jdzxsqx", ToolTypeName.jdzxsqx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "yssqx", ToolTypeName.yssqx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "jdzxpwx", ToolTypeName.jdzxpwx));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "yspwx", ToolTypeName.yspwx));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("曲线方程", 41, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.gjqxfczqx));
            //自定义
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "ball_pen", ToolTypeName.yzb));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "Highlighter", ToolTypeName.ygb));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("刷子", 32, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.sz));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "eraser", ToolTypeName.qyxp));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "text", ToolTypeName.wb));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "picture", ToolTypeName.tp));
            //计算
            ToolsWindowData.ToolGroups.Add(gp = new ListViewGroup());
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "distance", ToolTypeName.ldjl));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "dxjl", ToolTypeName.ddzxdjl));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "lzxjl", ToolTypeName.lzxjl));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("周长", 36, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.zc));
            //ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem("面积", 35, gp));
            //ToolsWindowData.ToolInfos.Add(new ToolsWindow.ToolInfo(ToolTypeName.mj));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "lzxjj", ToolTypeName.lzxjj));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "lzxdj", ToolTypeName.lzxdj));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "sdjd", ToolTypeName.sdjd));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "lxlslj", ToolTypeName.lxldslj));
            ToolsWindowData.ToolItems.Add(new ToolsWindow.ToolItem(gp, "lxlxlj", ToolTypeName.lxldxlj));
        }
        protected override void WndProc(ref Message m)
        {
            //switch (m.Msg)
            //{
            //    case Flags.WM_COPYDATA:
            //        MessageContent msg = (MessageContent)m.GetLParam(typeof(MessageContent));
            //        Program.AdministratorHandle = new IntPtr(int.Parse(msg.lpData));
            //        return;
            //}
            if (m.Msg == 163 && ClientRectangle.Contains(PointToClient(new Point(m.LParam.ToInt32()))) &&
                m.WParam.ToInt32() == 2)
            {
                m.WParam = new IntPtr(1);
            }
            base.WndProc(ref m);
            if (m.Msg == 132 && m.Result.ToInt32() == 1)
            {
                m.Result = new IntPtr(2);
            }
        }
        private void SplashScreenWindow_Load(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            lblStatus.Text = e.UserState.ToString();
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Program.LaunchCancelled = e.Cancelled;
            Close();
        }
        
        private void lblClose_Click(object sender, EventArgs e)
        {
            backgroundWorker1.CancelAsync();
        }

        private void lblClose_MouseEnter(object sender, EventArgs e)
        {
            lblClose.ForeColor = Color.White;
        }

        private void lblClose_MouseDown(object sender, MouseEventArgs e)
        {
            lblClose.ForeColor = Color.LightGray;
        }

        private void lblClose_MouseLeave(object sender, EventArgs e)
        {
            lblClose.ForeColor = Color.DarkSeaGreen;
        }

        private void lblClose_MouseUp(object sender, MouseEventArgs e)
        {
            lblClose.ForeColor = Color.White;
        }
    }
}
